package com.lei.s04session.service.impl;

import com.lei.s04session.dao.UserDao;
import com.lei.s04session.dao.impl.UserDaoImpl;
import com.lei.s04session.entity.LoginLog;
import com.lei.s04session.service.LoginLogService;
import com.lei.s04session.service.UserService;

public class UserServiceImpl implements UserService {
	private UserDao useDao = new UserDaoImpl();
	private LoginLogService loginLogService = new LoginLogServiceImpl();
	@Override
	public boolean login(String userName, String password,String ip) {
		boolean success = useDao.login(userName, password);
		LoginLog loginLog = buildLoginLog(userName, success,ip);
		loginLogService.add(loginLog);
		return success;
	}
	private LoginLog buildLoginLog(String userName, boolean success,String ip) {
		LoginLog loginLog = new LoginLog();
		loginLog.setStatus(success?"1":"2");
		loginLog.setUserName(userName);
		loginLog.setIp(ip);
		return loginLog;
	}
}
